package main

import (
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"fmt"
	"time"

	pb "./protobuf"
)

func main() {
	clientAddress := ":50051"
	// clientAddress := "192.168.65.3:50051"
	// clientAddress := "172.20.0.2:50051"
	// Set up a connection to the server.
	conn, err := grpc.Dial(clientAddress, grpc.WithInsecure(), grpc.WithTimeout(3*time.Second))
	if err != nil {
		panic(err)
	}
	defer conn.Close()
	// client
	client := pb.NewKgTestClient(conn)
	// testHandler
	var testHandler KgTestClient2

	testHandler.SayHello(client)
}

type KgTestClient2 struct{}

func (s *KgTestClient2) SayHello(client pb.KgTestClient) {
	req := &pb.HelloRequest{Name: "HelloWorld"}
	result, err := client.SayHello(context.Background(), req)

	if err != nil {
		fmt.Println("SayHello fail : ", err)
		return
	}
	fmt.Printf("SayHello success : %#v \n", result)
}
